//
//  SBButton.m
//  SharingBikes
//
//  Created by 李经纬 on 2017/3/27.
//  Copyright © 2017年 李经纬. All rights reserved.
//

#import "SBButton.h"

#define SBButtonImageRatio 0.6

@implementation SBButton

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 图标居中
        self.imageView.contentMode = UIViewContentModeBottom;
        // 文字居中
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        // 字体大小
        self.titleLabel.font = [UIFont systemFontOfSize:15.0];
        // 文字颜色
       [self setTitleColor: [UIColor colorWithHexString:@"333333"] forState:(UIControlStateNormal)];
    }
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    // 图标居中
    self.imageView.contentMode = UIViewContentModeBottom;
    // 文字居中
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    // 字体大小
    self.titleLabel.font = [UIFont systemFontOfSize:15.0];
    // 文字颜色
//    [self setTitleColor:SBRGBColor16Bit(0x333333) forState:(UIControlStateNormal)];
}

// 取消高亮状态
- (void)setHighlighted:(BOOL)highlighted{}

// 内部图片的frame
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat imageW = contentRect.size.width;
    CGFloat imageH = contentRect.size.height * SBButtonImageRatio;
    return CGRectMake(0, 0, imageW, imageH);
}

// 内部文字的frame
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat titleY = contentRect.size.height * SBButtonImageRatio;
    CGFloat titleW = contentRect.size.width;
    CGFloat titleH = contentRect.size.height - titleY;
    return CGRectMake(0, titleY, titleW, titleH);
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    // 图标居中
    self.imageView.contentMode = UIViewContentModeBottom | UIViewContentModeCenter;
    // 文字居中
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
